<template>
  <view class="reviews-card">
    <view class="section-title">用户评价</view>
    
    <view v-if="reviews.length === 0" class="no-reviews">
      <text>暂无评价</text>
    </view>
    
    <view v-else class="reviews-list">
      <view class="review-item" v-for="(review, index) in reviews" :key="index">
        <view class="review-header">
          <image :src="review.avatar" class="reviewer-avatar"></image>
          <view class="reviewer-info">
            <text class="reviewer-name">{{ review.username }}</text>
            <view class="review-rating">
              <text v-for="i in 5" :key="i" class="star" :class="{ 'filled': i <= review.rating }">★</text>
            </view>
          </view>
          <text class="review-date">{{ review.date }}</text>
        </view>
        <text class="review-content">{{ review.content }}</text>
      </view>
    </view>
    
    <view class="view-more" v-if="reviews.length > 0 && hasMore" @tap="loadMore">
      <text>查看更多评价</text>
      <uni-icons type="bottom" size="14" color="#999999"></uni-icons>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref, defineProps, defineEmits } from 'vue';
import type { PropType } from 'vue';

interface Review {
  username: string;
  avatar: string;
  rating: number;
  date: string;
  content: string;
  images?: string[];
}

const props = defineProps({
  dishId: {
    type: Number,
    required: true
  },
  reviews: {
    type: Array as PropType<Review[]>,
    default: () => []
  },
  hasMore: {
    type: Boolean,
    default: false
  }
});

const emit = defineEmits(['load-more']);

// 加载更多评价
const loadMore = () => {
  emit('load-more');
};
</script>

<style lang="scss" scoped>
@use '@/styles/variables.scss' as vars;

.reviews-card {
  background-color: #ffffff;
  border-radius: 12rpx;
  padding: 20rpx;
  margin-top: 20rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
}

.section-title {
  font-size: 30rpx;
  font-weight: 500;
  margin-bottom: 20rpx;
  position: relative;
  padding-left: 20rpx;
}

.section-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 6rpx;
  height: 24rpx;
  background-color: #07C160;
  border-radius: 3rpx;
}

.no-reviews {
  padding: 40rpx 0;
  text-align: center;
  color: #999;
  font-size: 28rpx;
}

.reviews-list {
  margin-top: 10rpx;
}

.review-item {
  padding: 20rpx 0;
  border-bottom: 1px solid #f0f0f0;
}

.review-header {
  display: flex;
  align-items: center;
  margin-bottom: 10rpx;
}

.reviewer-avatar {
  width: 64rpx;
  height: 64rpx;
  border-radius: 50%;
  margin-right: 16rpx;
}

.reviewer-info {
  flex: 1;
}

.reviewer-name {
  font-size: 28rpx;
  font-weight: 500;
  margin-bottom: 8rpx;
  display: block;
}

.review-rating {
  display: flex;
  align-items: center;
}

.star {
  color: vars.$warning-color;
  font-size: 24rpx;
  margin-right: 4rpx;
}

.star.filled {
  color: #FFA000;
}

.review-date {
  font-size: 24rpx;
  color: #999;
}

.review-content {
  font-size: 28rpx;
  line-height: 1.5;
  color: #333;
  display: block;
  margin-top: 10rpx;
}

.view-more {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20rpx 0;
  color: #666;
  font-size: 26rpx;
}
</style> 